
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static int solution(int n, int H, int A, int[] h, int[] a) {
        // 筛选可击败的怪物
        List<int[]> candidates = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (h[i] < H && a[i] < A) {
                candidates.add(new int[]{h[i], a[i]});
            }
        }

        if (candidates.isEmpty()) {
            return 0;
        }

        // 初始化DP数组
        int[] dp = new int[candidates.size()];
        for (int i = 0; i < dp.length; i++) {
            dp[i] = 1;
        }

        // 动态规划求解
        for (int i = 1; i < candidates.size(); i++) {
            for (int j = 0; j < i; j++) {
                if (candidates.get(i)[0] > candidates.get(j)[0] 
                    && candidates.get(i)[1] > candidates.get(j)[1]) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
        }

        // 找出最大值
        int maxLen = 0;
        for (int num : dp) {
            if (num > maxLen) {
                maxLen = num;
            }
        }
        return maxLen;
    }

    public static void main(String[] args) {
        System.out.println(solution(3, 4, 5, new int[]{1, 2, 3}, new int[]{3, 2, 1}) == 1);
        System.out.println(solution(5, 10, 10, new int[]{6, 9, 12, 4, 7}, new int[]{8, 9, 10, 2, 5}) == 2);
        System.out.println(solution(4, 20, 25, new int[]{10, 15, 18, 22}, new int[]{12, 18, 20, 26}) == 3);
        System.out.println(solution(13, 8, 7, 
            new int[]{8, 4, 1, 5, 11, 8, 8, 8, 3, 2, 13, 1, 16},
            new int[]{16, 7, 6, 7, 8, 1, 9, 14, 14, 3, 12, 14, 11}) == 1);
    }
}
